#ifndef DOUBAN_MINIBLOG_REPLYVIEWER_H
#define DOUBAN_MINIBLOG_REPLYVIEWER_H

#include "douban_global.h"
#include "MiniBlogEntry.h"
#include <QStandardItemModel>
#include <QXmlStreamReader>
#include <QTextBrowser>
#include <QPushButton>
#include <QListView>
#include <QTextEdit>
#include <QAction>
#include <QTimer>
#include <QMovie>
#include <QLabel>
#include <QMenu>
class QNetworkReply;

namespace Douban
{
	class MiniBlogEntry;
	class DoubanContext;
	class ReplyViewer : QFrame
	{
		Q_OBJECT
		public:
			void setAutoClose(bool a) { b_autoClose = a; }
			void viewEntry(MiniBlogEntry* entry);





			ReplyViewer(DoubanContext* c);
			~ReplyViewer();
			bool eventFilter(QObject *, QEvent *);
		protected:
			void closeEvent(QCloseEvent*);
		private:
			DoubanContext*		m_context;
			bool	b_autoClose;
			int		i_tryToDeleteCommentIndex;

			QLabel			m_avatarIcon;
			QLabel			m_contentLabel;
			QListView		m_replyListView;
			QTextEdit		m_replyText;
			QPushButton		m_replyBtn;
			QLabel			m_hintLabel;
			QTextBrowser		m_textCalc;
			QLabel			m_loadingLabel;
			QMovie			m_loadingMovie;
			QAction			m_deleteAct;
			QAction			m_mailAct;
			QAction			m_messageAct;
			QAction			m_visitUserPage;
			QMenu			m_listViewMenu;
			QTimer			m_iconCheckTimer;

			MiniBlogEntry*	m_currentEntry;

			QStandardItemModel	m_repliesModel;
			QXmlStreamReader m_xmlParser;

			QNetworkReply*	r_getCommentReply;
			QNetworkReply*	r_postNewCommentReply;
			QNetworkReply*	r_deleteCommentReply;

			QHash<MiniBlogEntryReply*,int> m_unavailableIcons;

			void cleanup();
			void showLoading();
			void hideLoading();

			void addComment(MiniBlogEntryReply*);
			void parseComment(const QByteArray& data,QList<MiniBlogEntryReply*>& comments);
		private slots:
			void iconAvailable();
			void checkIconIsReady();

			void onCustomContextMenu(const QPoint&);
			void onReceivedComments();
			void postReply();
			void postReplyFinished();
			void deleteReply(int index);
			void deleteReplyFinished();

			void openUrl(const QString&);
		private:
			static const QString Post_Entry;
			static const QString MiniBlog_Comments_URL;
			static const QString Recommendation_Comments_URL;
			static const QString Delete_MiniBlog_Comments_URL;
			static const QString Delete_Recommendation_Comments_URL;
			Q_DISABLE_COPY(ReplyViewer)
	};
}
#endif // REPLYVIEWER_H
